/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kreig133.spineviewer;

import com.kreig133.controller.Controller;
import com.kreig133.controller.TaskEnum;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//com.kreig133.spineviewer//SpineModel//EN",
autostore = false)
@TopComponent.Description(preferredID = "SpineModelTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "editor", openAtStartup = true)
@ActionID(category = "Window", id = "com.kreig133.spineviewer.SpineModelTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(displayName = "#CTL_SpineModelAction",
preferredID = "SpineModelTopComponent")
public final class SpineModelTopComponent extends TopComponent {

    public SpineModelTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(SpineModelTopComponent.class, "CTL_SpineModelTopComponent"));
        setToolTipText(NbBundle.getMessage(SpineModelTopComponent.class, "HINT_SpineModelTopComponent"));

    }
    
    //private final String[] checkboxModel = {"View Real Experiment", "View Experiment Result", "Experiment Process"};
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        settingFileField = new javax.swing.JTextField();
        setSettingFileButton = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        mainFileField = new javax.swing.JTextField();
        setMainFileButton = new javax.swing.JButton();
        ButtonWork = new javax.swing.JButton();
        centralPanel = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.GridLayout(1, 0));

        jPanel3.setPreferredSize(new java.awt.Dimension(843, 68));

        jComboBox1.setModel(new DefaultComboBoxModel(TaskEnum.values()));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel3.add(jComboBox1);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        settingFileField.setText(org.openide.util.NbBundle.getMessage(SpineModelTopComponent.class, "SpineModelTopComponent.settingFileField.text")); // NOI18N
        settingFileField.setPreferredSize(new java.awt.Dimension(350, 22));
        settingFileField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingFileFieldActionPerformed(evt);
            }
        });
        jPanel4.add(settingFileField);

        org.openide.awt.Mnemonics.setLocalizedText(setSettingFileButton, org.openide.util.NbBundle.getMessage(SpineModelTopComponent.class, "SpineModelTopComponent.setSettingFileButton.text")); // NOI18N
        setSettingFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setSettingFileButtonActionPerformed(evt);
            }
        });
        jPanel4.add(setSettingFileButton);

        jPanel2.add(jPanel4, new java.awt.GridBagConstraints());

        mainFileField.setText(org.openide.util.NbBundle.getMessage(SpineModelTopComponent.class, "SpineModelTopComponent.mainFileField.text")); // NOI18N
        mainFileField.setPreferredSize(new java.awt.Dimension(300, 22));
        mainFileField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainFileFieldActionPerformed(evt);
            }
        });
        jPanel6.add(mainFileField);

        org.openide.awt.Mnemonics.setLocalizedText(setMainFileButton, org.openide.util.NbBundle.getMessage(SpineModelTopComponent.class, "SpineModelTopComponent.setMainFileButton.text")); // NOI18N
        setMainFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setMainFileButtonActionPerformed(evt);
            }
        });
        jPanel6.add(setMainFileButton);

        org.openide.awt.Mnemonics.setLocalizedText(ButtonWork, org.openide.util.NbBundle.getMessage(SpineModelTopComponent.class, "SpineModelTopComponent.ButtonWork.text")); // NOI18N
        ButtonWork.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonWorkActionPerformed(evt);
            }
        });
        jPanel6.add(ButtonWork);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel2.add(jPanel6, gridBagConstraints);

        jPanel3.add(jPanel2);

        jPanel1.add(jPanel3);

        add(jPanel1, java.awt.BorderLayout.NORTH);

        centralPanel.setLayout(new java.awt.GridLayout(1, 1, 10, 10));
        add(centralPanel, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void setSettingFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setSettingFileButtonActionPerformed
        settingFileField.setText(Controller.openFile(this));
}//GEN-LAST:event_setSettingFileButtonActionPerformed

    private void mainFileFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainFileFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_mainFileFieldActionPerformed

    private void setMainFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setMainFileButtonActionPerformed
        mainFileField.setText(Controller.openFile(this));
}//GEN-LAST:event_setMainFileButtonActionPerformed

    private void ButtonWorkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonWorkActionPerformed
        String settingFile = settingFileField.getText();
        String mainFile = mainFileField.getText();
        if (settingFile == null || mainFile == null) {
            return;
        }
        JPanel panel = Controller.process((TaskEnum)jComboBox1.getSelectedItem(),this, settingFile, mainFile);
        try {
            if(panel!=null) {
                centralPanel.removeAll();
                centralPanel.add(panel);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        centralPanel.revalidate();
}//GEN-LAST:event_ButtonWorkActionPerformed

    private void settingFileFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingFileFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_settingFileFieldActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonWork;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel centralPanel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTextField mainFileField;
    private javax.swing.JButton setMainFileButton;
    private javax.swing.JButton setSettingFileButton;
    private javax.swing.JTextField settingFileField;
    // End of variables declaration//GEN-END:variables

    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
}
